//
//  QpFoodDetailsSecondViewController.m
//  Tour
//
//  Created by 才诗琦 on 16/3/11.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "QpFoodDetailsSecondViewController.h"

@interface QpFoodDetailsSecondViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataArr;
@property(nonatomic, strong)UIView *headerView;

@end

@implementation QpFoodDetailsSecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //创建tableView
    [self creatTableView];
//数据处理
    [self dataHandler];
    

}


- (void)dataHandler
{
     self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*2+ 100)];
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/footprint/poi_detail?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=89dd34fbffaaa72503b4baa7a9d02812&page=1&poi_id=%@",self.cellid];
    NSString *str = @"&screensize=640&track_app_channel=App%2520Store&track_app_version=6.8.3&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=CDA3EEEB-61BF-473E-AFFF-32B6332C9BBF&track_os=ios%25207.1.2&track_user_id=7328550&v=1";
    
    
    [AFNModel GETWithHandler:[NSString stringWithFormat:@"%@%@",url,str] completion:^(id result) {
       
        /**< 导航栏标题 */
        self.navigationItem.title = result[@"data"][@"chinesename"];
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 230)];
        [image sd_setImageWithURL:[NSURL URLWithString:result[@"data"][@"photo"]]placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
        [_headerView addSubview:image];

        // 店名
        UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, image.frame.size.height + 10, SCREEN_WIDTH, 20)];
        title.text = result[@"data"][@"chinesename"];
        [_headerView addSubview:title];

        // 线
        UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(0, title.frame.size.height + title.frame.origin.y+3 , SCREEN_WIDTH, 3)];
        line.text = @"________________________";
        line.textColor = [UIColor blackColor];
        [_headerView addSubview:line];

        // 简介
        UILabel *jianjie = [[UILabel alloc]initWithFrame:CGRectMake(10, line.frame.origin.y + line.frame.size.height + 10, 50, 20)];
        jianjie.text = @"简介";
        [_headerView addSubview:jianjie];

        // 简介内容
        UILabel *introduction = [[UILabel alloc]initWithFrame:CGRectMake(10, jianjie.frame.origin.y + jianjie.frame.size.height + 10, SCREEN_WIDTH - 20, 200)];
        introduction.text = result[@"data"][@"introduction"];
        introduction.textColor = [UIColor lightGrayColor];
        introduction.numberOfLines = 0;
        [_headerView addSubview:introduction];

        // 线
        UILabel *line2 = [[UILabel alloc]initWithFrame:CGRectMake(0, introduction.frame.size.height + introduction.frame.origin.y+3 , SCREEN_WIDTH, 1)];
        //        line2.text = @"___________________";
        line2.backgroundColor = [UIColor blackColor];
        [_headerView addSubview:line2];

        // 地址
        UILabel *addresstitle = [[UILabel alloc]initWithFrame:CGRectMake(10, line2.frame.origin.y + line2.frame.size.height + 10, SCREEN_WIDTH, 20)];
        addresstitle.text = @"地址";
        [_headerView addSubview:addresstitle];

        UILabel *address = [[UILabel alloc]initWithFrame:CGRectMake(10, addresstitle.frame.origin.y + addresstitle.frame.size.height + 10, SCREEN_WIDTH - 20, 20)];
        address.text = result[@"data"][@"address"];
        address.textColor = [UIColor lightGrayColor];
        [_headerView addSubview:address];

        // 路线
        UILabel *waytotitle = [[UILabel alloc]initWithFrame:CGRectMake(10, address.frame.origin.y + address.frame.size.height + 10, SCREEN_WIDTH, 20)];
        waytotitle.text = @"路线";
        [_headerView addSubview:waytotitle];

        UILabel *wayto = [[UILabel alloc]initWithFrame:CGRectMake(10, waytotitle.frame.origin.y + waytotitle.frame.size.height + 10, SCREEN_WIDTH - 20, 150)];
        wayto.text = result[@"data"][@"wayto"];
        wayto.textColor = [UIColor lightGrayColor];
        wayto.numberOfLines = 0;
        [_headerView addSubview:wayto];

        // 电话
        UILabel *tele = [[UILabel alloc]initWithFrame:CGRectMake(10, wayto.frame.origin.y + wayto.frame.size.height + 10, SCREEN_WIDTH, 20)];
        tele.text = @"电话";
        [_headerView addSubview:tele];

        UILabel *telephone = [[UILabel alloc]initWithFrame:CGRectMake(10, tele.frame.origin.y + tele.frame.size.height + 10, SCREEN_WIDTH - 20, 20)];
        telephone.text = result[@"data"][@"phone"];
        telephone.textColor = [UIColor lightGrayColor];
        [_headerView addSubview:telephone];

        // 打电话
        UIButton *call = [UIButton buttonWithType:UIButtonTypeSystem];
        call.frame = CGRectMake(SCREEN_WIDTH - 40, tele.frame.origin.y + tele.frame.size.height + 10, 20, 20);
        [call setImage:[UIImage imageNamed:@"iconfont-dianhua"] forState:UIControlStateNormal];
        [call setTintColor:[UIColor greenColor]];
        [_headerView addSubview:call];
        [call addTarget:self action:@selector(call:) forControlEvents:UIControlEventTouchUpInside];
        // 时间
        UILabel *timelabel = [[UILabel alloc]initWithFrame:CGRectMake(10, telephone.frame.origin.y + telephone.frame.size.height + 10, SCREEN_WIDTH, 20)];
        timelabel.text = @"时间";
        [_headerView addSubview:timelabel];

        UILabel *time = [[UILabel alloc]initWithFrame:CGRectMake(10, timelabel.frame.origin.y + timelabel.frame.size.height + 10, SCREEN_WIDTH - 20, 50)];
        time.text = result[@"data"][@"opentime"];
        time.numberOfLines = 0;
        time.textColor = [UIColor lightGrayColor];
        [_headerView addSubview:time];

        // 门票
        UILabel *ticket = [[UILabel alloc]initWithFrame:CGRectMake(10, time.frame.origin.y + time.frame.size.height + 10, SCREEN_WIDTH, 20)];
        ticket.text = @"门票";
        [_headerView addSubview:ticket];

        UILabel *price = [[UILabel alloc]initWithFrame:CGRectMake(10, ticket.frame.origin.y + ticket.frame.size.height + 10, SCREEN_WIDTH - 20, 20)];
        price.text = result[@"data"][@"price"];
        price.textColor = [UIColor lightGrayColor];
        [_headerView addSubview:price];

        // 设置headerView 为tableHeaderView
        self.tableView.tableHeaderView = _headerView;
        [self.tableView reloadData];
    }];
    
}
#pragma mark - 打电话
- (void)call:(UIButton *)btn
{
    NSURL *url = [NSURL URLWithString:@"tel://10086"];
    
    [[UIApplication sharedApplication] openURL:url];
}
#pragma mark - 创建tableview
- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    // 注册重用池
    [_tableView registerClass:[QpFoodDetailsSecondTableViewCell class] forCellReuseIdentifier:@"cell"];

}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    QpFoodDetailsSecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
